|
|
|
|
|
|
|
You can use each of the preceding methods to draw on an object. Before I cover each method in more detail, though, I should mention that certain properties of the object being drawn on affect the way these methods work. These properties are listed in Table 19.2. |
|
|
|
|
| Table 19.2 Drawing Properties That Affect the Appearance of Graphics | | Property Name | Purpose | | DrawMode | Determines how the drawing color interacts with the colors already present on the object | | DrawStyle | Sets a drawing pattern | | DrawWidth | Sets the border width of lines and circles | | FillColor | Determines the color used to fill a rectangle or circle | | FillStyle | Determines the pattern used to fill a rectangle or circle | | ForeColor | Determines the primary color used to draw with the graphics methods, if no color is specified in the method call | | AutoRedraw | Determines whether the output of the graphics methods is automatically refreshed when the window has been obscured (Form and PictureBox only) |
|
|
|
|
|
|
You use the Line method to draw lines and boxes. To draw lines, supply the starting and ending points of the line on a coordinate system whose origin is in the upper-left corner. The following statements, for example, draw a green line from the upper-left corner of a form to the lower-right corner: |
|
|
|
|
|
|
|
|
Dim x2 As Single, y2 As Single
x2 = Form1.ScaleWidth
y2 = Form1.ScaleHeight
Line (0, 0)-(x2, y2),vbGreen |
|
|
|
|
|
|
|
|
If you omit the starting point of the line, the current position becomes the starting point. The current position is the ending point of the last line, or you can set it with the object's CurrentX and CurrentY properties. For example, the following code uses the Line method to draw a triangle on a form. In each call to the Line method, note that the first set of coordinates is omitted. |
|
|
|
|
|
|
|
|
Private Sub Form_Click()
Form1.CurrentX = 1500
Form1.CurrentY = 750
Line -(2000, 750), vbRed
Line -(2000, 1250), vbBlue
Line -(1500, 750)
End Sub |
|
|
|
|
|
|
|
|
In the last of the preceding code segment statements, the optional parameter for the color of the line is omitted. If no color is specified, the line is drawn in the color specified in the object's |
|
|
|
|
|